package com.atguigu.day04.test;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/2 15:49
 * @注释 买可乐
 */
public class LoopExer {
    public static void main(String[] args) {
        int sum = 0;
        int i = 20;//总金额
        int unit = 3;
        int bottle = 0;
        int resMoney = 0;
        //while循环
        while(i >= unit){
            bottle = i / unit;
            resMoney = i % unit;
            sum += bottle;
            i = bottle + resMoney;
        }

        //for循环

        /*//一瓶一瓶购买
        for(;i >= unit;){
            i -= unit;
            sum++;
            i++;
        }

        //do-while语句
        //一瓶一瓶购买
        do{
            i -= unit;
            sum++;
            i++;
        }while(i >= 3);*/
        System.out.println("sum = " + sum);


    }
}
